// saves options to & restores options from localStorage.

function save_options() {
	
	if (window.localStorage == null) {
		alert('local storage is required for storing options.');
		return;
	}

	var select = document.getElementById("color");
	var color = select.children[select.selectedIndex].value;
	window.localStorage.highlightcolor = color;

	//var select = document.getElementById("realtime");
	//var realtime = select.children[select.selectedIndex].value;
	//window.localStorage.realtimesearch = realtime;
	window.localStorage.realtimesearch = "-1";
	
	var status = document.getElementById("status");
	status.innerHTML = "Options have been saved.";
	setTimeout(function() { status.innerHTML = ""; }, 1000);
}

// offer button to save if an option is changed
function set_changed() {
  var status = document.getElementById("status");
  status.innerHTML = "<button onclick=\"save_options()\">Save options</button>";
}


// Restores select box states to saved values from localStorage.
function restore_options() {
   if (window.localStorage == null) {
    alert('local storage is required for storing options.');
    return;
  }
  
   var highlightcolor = window.localStorage.highlightcolor;
   if (typeof highlightcolor === "undefined"){
	   highlightcolor="yellow";
  }
   set_selected("color", highlightcolor);
   
   //var realtime = window.localStorage.realtimesearch;
   //if (typeof realtime === "undefined"){
   realtime="-1";
   //}
   //set_selected("realtime", realtime);
}


function set_selected(id_name, valueToSelect) {
	var select = document.getElementById(id_name);

	for (var i = 0; i < select.children.length; i++) {
		var child = select.children[i];
		if (child.value == valueToSelect) {
			child.selected = "true";
			break;
		}
	}
}
